<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function callOtherDomain(url) {
      // 1.创建xhr请求对象
      let xhr = new XMLHttpRequest()
        // 2.打开请求
      xhr.open('GET', url, true)
        // 3.回调函数
      xhr.onreadystatechange = function() {
          // 0 未初始化 1 opened 2 HEADERS_RECEIVED 3 Loading 4 Received 
          if (this.readyState === 4) {
            if (this.status >= 200 && this.status < 300) {
              console.log(this.responseText);
            }
          }
        }
        // 4.发送请求
      xhr.send()
    }
    callOtherDomain('http://www.baidu.com')
  </script>
</body>

</html>